const { selected } = require("../../utils/util")
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    // isVisible: {
    //   type: Boolean,
    //   value: true
    // },
    title: {
      type: String,
      value: '标题'
    },
    optionalList: {
      type: Array,
      value: [
        {
          type: "tag", name: "标签", list: [
            { name: "历史", eName: "lishi" },
            { name: "励志", eName: "lizhi" },
            { name: "青春", eName: "lishi" },
            { name: "故事", eName: "lizhi" },
            { name: "儿童", eName: "lishi" },
            { name: "校园", eName: "lizhi" },
            { name: "教育", eName: "lishi" },
          ]
        },
      ]
    },
    animateDisabled: {
      type: Boolean,
      value: false
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    isHidden: true,
    animationData: {},
    selectedData: [
      // {
      //   superclass: "标签",
      //   subclass: ["历史"]
      // }
    ],
    isSelect: 1
  },

  /**
   * 组件的方法列表
   */
  methods: {
    selectComplete() {
      this.hide()
      this.triggerEvent("emitSelected", this.data.selectedData)
    },
    select(e) {
      const dataset = e.currentTarget.dataset
      selected(this.data.selectedData, dataset.superclass, dataset.subclass, this)
    },
    reset() {
      this.setData({
        selectedData: []
      })
    },
    show: function () {
      // console.log(this.data);
      if (this.data.animateDisabled) {
        this.setData({ isHidden: false });
      } else {
        const animation = wx.createAnimation({
          duration: 5000,
          timingFunction: 'ease-in-out'
        });
        animation.opacity(1).step();
        this.setData({
          animationData: animation.export(),
          isHidden: false
        });
      }
    },
    hide: function () {
      if (this.data.animateDisabled) {
        this.setData({ isHidden: true });
      } else {
        const animation = wx.createAnimation({
          duration: 5000,
          timingFunction: 'ease-in-out'
        });
        animation.opacity(0).step();
        this.setData({
          animationData: animation.export(),
          isHidden: true
        });
      }
    },
    hiddenPopup() {
      this.hide()
    },
    preventTouchMove() {
      // 防止滚动穿透
      return false
    },
  }
})
